package crud;

import org.hibernate.Session;
import org.junit.Test;

import Domain.News;
import utils.HibernateUtils;

public class TestUpdate {
	
	@Test
	public void tesUpdate() {
		Session session = HibernateUtils.getSession();
		
		try {
			session.beginTransaction();
				
			//删除 修改都是根据id 判断的
			News name = new News("360收购腾讯","荆楚新闻网");
			name.setId(2);
			session.update(name);
			
			session.getTransaction().commit();
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		
	}
	
	@Test
	public void tesSaveUpdate() {
		Session session = HibernateUtils.getSession();
		
		try {
			session.beginTransaction();
				
			//删除 修改都是根据id 判断的
			News name = new News("腾讯收购360","晨光新闻网");
			name.setId(4);
			//执行save update 看是否存在id
			session.saveOrUpdate(name);
			
			session.getTransaction().commit();
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		
	}

}
